$(function () {
    //分类更多
    sortMoreFun();

    queryTeacherListData(1);
    //获取课程页面数据列表
    function queryTeacherListData(pageNo) {
        var subjectId = $("#subjectId").val();
        var isQuestionOrder = $("#isQuestionOrder").val();
        var teacherIdentity = $("#teacherIdentity").val();
        var params = {"subjectIds":subjectId,"isQuestionOrder":isQuestionOrder,"teacherIdentity":teacherIdentity};
        var _params = JSON.stringify(params);
        getPageAjaxData({
            url: baseloaction + '/web/teacher/ajaxTeacherList',
            contextId: 'teacher-list-context',
            pageNo: pageNo,
            params: _params,
            pageCall: queryTeacherListData,
            callback: function (pageNo) {
                lazyTeacherImage();
            }
        });
    }

    findSubjectList(function (result) {
        var allSubject = result;
        var parentSubjectList = allSubject[0];
        if (parentSubjectList != null && parentSubjectList.length > 0) {
            var context = '<li data-id="" class="cm-filter-item parent-subject active">全部</li>';
            $.each(parentSubjectList, function (i, e) {
                context += '<li data-id="' + e.id + '" class="cm-filter-item parent-subject">' + e.subjectName + '</li>';
            });
            $("#subject-list-parent").html(context);
            //分类更多
            sortMoreFun();
            //点击父级专业
            $("body").on('click', ".parent-subject", function () {
                var _this = $(this);
                _this.addClass('active').siblings('#subject-list-parent>.cm-filter-item').removeClass('active');
                var parentId = _this.data('id');
                $("#subjectId").val(parentId);
                queryTeacherListData(1);
                var childList = allSubject[parentId];
                if (childList != null && childList.length > 0) {
                    $("#child-subject-list").removeClass('hide');
                    context = '<li data-id="' + parentId + '" class="cm-filter-item active">全部</li>';
                    $.each(childList, function (index, em) {
                        context += '<li class="cm-filter-item" data-id="' + em.id + '">' + em.subjectName + '</li>';
                    });
                    $("#child-subject-list ul").html(context);
                    sortMoreFun();
                    //点击子级专业
                    $("#child-subject-list ul>li").click(function () {
                        var _th = $(this);
                        var _subjectId = _th.data('id');
                        _th.addClass('active').siblings('#child-subject-list li').removeClass('active');
                        $("#subjectId").val(_subjectId);
                        queryTeacherListData(1);
                    });
                    sortMoreFun();
                } else {
                    $("#child-subject-list").addClass('hide');
                }
            });
        }
    });
});